<template>
  <div class="app-container">
    <div class="talkBox">
      <div class="header"></div>
      <ul>
        <li
          v-for="(item, index) in loglist"
          :key="index"
          :class="index % 2 == 0 ? 'aiStyle' : 'humanStyle'"
        >
          <div v-if="index % 2 == 0">
            <img src="@/assets/images/ai.png" alt="" />
            <div class="toolBoxStyle">
              <img style="width: 12px; height: 12px" src="@/assets/images/copy.png" alt="" />
            </div>
          </div>
          <div v-else>
            <div class="toolBoxStyle">
              <img style="width: 12px; height: 12px" src="@/assets/images/copy.png" alt="" />
            </div>
            <img src="@/assets/images/human.png" alt="" />
          </div>
          <p v-html="item.content"></p>
        </li>
      </ul>
      <div class="sendMsg">
        <!-- <div
          class="custom-input"
          contenteditable="true"
          @input="handleInput"
          @focus="handleFocus"
          @blur="handleBlur"
          @keydown="handleKeydown"
        >
          <span v-if="!inputValue && !isFocused" class="placeholder">{{ placeholder }}</span>
          <span v-else>{{ inputValue }}</span>
          <span
            class="sendStyle"
            @click="handleKeydown"
            :loading="isLoading"
            :size="loadingSize"
            el-button
            ><img src="@/assets/images/send.png" alt=""
          /></span>
          <span class="sendStyle" ref="loadRef"><img src="@/assets/images/send.png" alt="" /></span>
        </div> -->
        <div class="input-area">
          <el-input
            v-model="messageContent"
            placeholder="输入问题，发送 [Enter]/换行 [Ctrl(Alt/Shift) + Enter]"
            style="width: calc(100% - 80px)"
          ></el-input>
          <el-button @click="sendMessage" :loading="isSending">发送</el-button>
        </div>
        <!-- <el-input
          v-model=""
          @keydown="handleKeydown"
          placeholder="输入问题，发送 [Enter]/换行 [Ctrl(Alt/Shift) + Enter]"
          :suffix-icon="Promotion"
        /> -->
      </div>
    </div>
  </div>
</template>

<script setup name="voiceTest">
import { Promotion } from "@element-plus/icons-vue"
import { ElLoading } from "element-plus"
const loglist = ref([
  {
    content: "11111111",
  },
  {
    content: "2222222",
  },
  {
    content: "3333333",
  },
])
const messageContent = ref()
const loadRef = ref()
const loadRefInstance = ref()
// 创建响应式数据
const inputValue = ref("")
// 用于控制 placeholder 是否显示
const isFocused = ref(false)
// 定义 placeholder 文本
const placeholder = ref("输入问题，发送 [Enter]/换行 [Ctrl(Alt/Shift) + Enter]")
// 处理输入事件
const handleInput = (event) => {
  // 更新响应式数据
  inputValue.value = event.target.textContent
}
// 处理聚焦事件
const handleFocus = () => {
  isFocused.value = true
}
// 处理失焦事件
const handleBlur = () => {
  isFocused.value = false
}

// 控制加载状态
const isLoading = ref(false)
// 设置加载图标的大小
const loadingSize = ref("small")
// 回车事件
const handleKeydown = () => {
  console.log(1111111111)

  isLoading.value = true
  //

  // isLoading.value = false;
  // inputValue.value = ""
}
</script>

<style scoped lang="scss">
.app-container {
  width: 100%;
  height: 100%;
}
.talkBox {
  width: 100%;
  height: 100%;
  background-color: #fff;
  border-radius: 15px;
  position: relative;
  .header {
    height: 50px;
    width: 100%;
    background-color: #fbfbfc;
  }
  ul {
    padding: 10px 30px;
    .humanStyle {
      // text-align: right;
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      div {
        text-align: right;
        margin-bottom: 5px;
        display: flex;
        .toolBoxStyle {
          padding: 8px 10px;
          border: 1px solid #e2eaff;
          border-radius: 5px;
          margin-right: 6px;
        }
        img {
          width: 25px;
          height: 25px;
        }
      }
      p {
        display: inline-block;
        padding: 10px 20px;
        border-radius: 10px 0px 10px 10px;
        background-color: #e2eaff;
      }
    }
    .aiStyle {
      div {
        margin-bottom: 5px;
        display: flex;
        .toolBoxStyle {
          padding: 8px 10px;
          border: 1px solid #e2eaff;
          border-radius: 5px;
          margin-left: 6px;
        }
        img {
          width: 25px;
          height: 25px;
        }
      }
      p {
        display: inline-block;
        padding: 10px 20px;
        border-radius: 0px 10px 10px 10px;
        background-color: #f7f8fa;
      }
    }
  }
  .sendMsg {
    position: absolute;
    bottom: 2%;
    left: 22%;
    width: 55%;
    border: 1px solid #ccc;
    margin: auto;
    border-radius: 10px;
    box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 8px;
    :deep(.el-input__wrapper) {
      border-radius: 10px;
    }
    :deep(.el-input__inner) {
      border-radius: 15px;
      padding: 25px !important;
    }
    /* 模拟输入框样式 */
    .custom-input {
      display: flex;
      justify-content: space-between;
      width: 100%;
      padding: 16px;
      border: 1px solid #ccc;
      border-radius: 4px;
      outline: none;
      min-height: 30px;
      overflow: auto;
    }
    /* 聚焦时的样式 */
    .custom-input:focus {
      border-color: #5d22c2;
      box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    }
    /* placeholder 样式 */
    .placeholder {
      font-size: 14px;
      color: #999;
    }
    .sendStyle {
      width: 25px;
      height: 25px;
      cursor: pointer;
    }
  }
}
</style>
